package pri.damai.xiaowu.goods.server.api.rpc;

import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import pri.damai.xiaowu.common.core.form.IdForm;
import pri.damai.xiaowu.common.core.vo.ResultVO;
import pri.damai.xiaowu.common.dubbo.anno.DubboHandler;
import pri.damai.xiaowu.goods.client.SkuService;
import pri.damai.xiaowu.goods.common.command.SkuCreateCommand;
import pri.damai.xiaowu.goods.common.command.StockReduceCmd;
import pri.damai.xiaowu.goods.common.vo.GoodsInfoVO;
import pri.damai.xiaowu.goods.server.entity.ProductSku;
import pri.damai.xiaowu.goods.server.service.impl.ProductSkuServiceImpl;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * @Desc
 * @Author DaMai
 * @Date 2022/3/23 13:53
 * 但行好事，莫问前程。
 */
@DubboService
public class SkuDubboService implements SkuService {

    @Resource
    ProductSkuServiceImpl skuService;

    @Override
    @DubboHandler
    public ResultVO<Void> createSku(SkuCreateCommand skuCreateCommand) {

        ProductSku productSku = new ProductSku();
        BeanUtils.copyProperties(skuCreateCommand, productSku);

        skuService.save(productSku);

        return ResultVO.success();
    }

    @Override
    @DubboHandler
    public ResultVO<Void> reduceSku(StockReduceCmd stockReduceCmd) {
        skuService.reduceSkuStock(stockReduceCmd);
        return ResultVO.success();
    }

    @Override
    @DubboHandler
    public ResultVO<Void> reduceSkus(List<StockReduceCmd> stockReduceCmds) {
        skuService.reduceSkuStock(stockReduceCmds);
        return ResultVO.success();
    }

    @Override
    public ResultVO<GoodsInfoVO> getSkuById(IdForm idForm) {
        return null;
    }

}
